.class final Lcom/ninesky/browser/ab;
.super Ljava/lang/Thread;

# interfaces
.implements Landroid/content/DialogInterface$OnCancelListener;
.implements Landroid/view/View$OnClickListener;


# instance fields
.field private a:Ljava/net/URL;

.field private b:Landroid/app/ProgressDialog;

.field private c:Z

.field private synthetic d:Lcom/ninesky/browser/n;


# direct methods
.method public constructor <init>(Lcom/ninesky/browser/n;Ljava/lang/String;)V
    .locals 1

    iput-object p1, p0, Lcom/ninesky/browser/ab;->d:Lcom/ninesky/browser/n;

    invoke-direct {p0}, Ljava/lang/Thread;-><init>()V

    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/ninesky/browser/ab;->c:Z

    :try_start_0
    new-instance v0, Ljava/net/URL;

    invoke-direct {v0, p2}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

    iput-object v0, p0, Lcom/ninesky/browser/ab;->a:Ljava/net/URL;
    :try_end_0
    .catch Ljava/net/MalformedURLException; {:try_start_0 .. :try_end_0} :catch_0

    :goto_0
    return-void

    :catch_0
    move-exception v0

    const/4 v0, 0x0

    iput-object v0, p0, Lcom/ninesky/browser/ab;->a:Ljava/net/URL;

    goto :goto_0
.end method


# virtual methods
.method public final onCancel(Landroid/content/DialogInterface;)V
    .locals 1

    const/4 v0, 0x1

    iput-boolean v0, p0, Lcom/ninesky/browser/ab;->c:Z

    return-void
.end method

.method public final onClick(Landroid/view/View;)V
    .locals 4

    const/4 v3, 0x1

    iget-object v0, p0, Lcom/ninesky/browser/ab;->a:Ljava/net/URL;

    if-eqz v0, :cond_0

    new-instance v0, Landroid/app/ProgressDialog;

    iget-object v1, p0, Lcom/ninesky/browser/ab;->d:Lcom/ninesky/browser/n;

    invoke-static {v1}, Lcom/ninesky/browser/n;->a(Lcom/ninesky/browser/n;)Lcom/ninesky/browser/BrowserActivity;

    move-result-object v1

    invoke-direct {v0, v1}, Landroid/app/ProgressDialog;-><init>(Landroid/content/Context;)V

    iput-object v0, p0, Lcom/ninesky/browser/ab;->b:Landroid/app/ProgressDialog;

    iget-object v0, p0, Lcom/ninesky/browser/ab;->b:Landroid/app/ProgressDialog;

    invoke-virtual {v0, v3}, Landroid/app/ProgressDialog;->setIndeterminate(Z)V

    iget-object v0, p0, Lcom/ninesky/browser/ab;->b:Landroid/app/ProgressDialog;

    iget-object v1, p0, Lcom/ninesky/browser/ab;->d:Lcom/ninesky/browser/n;

    invoke-static {v1}, Lcom/ninesky/browser/n;->a(Lcom/ninesky/browser/n;)Lcom/ninesky/browser/BrowserActivity;

    move-result-object v1

    invoke-virtual {v1}, Lcom/ninesky/browser/BrowserActivity;->getResources()Landroid/content/res/Resources;

    move-result-object v1

    const v2, 0x7f0700da

    invoke-virtual {v1, v2}, Landroid/content/res/Resources;->getText(I)Ljava/lang/CharSequence;

    move-result-object v1

    invoke-virtual {v0, v1}, Landroid/app/ProgressDialog;->setMessage(Ljava/lang/CharSequence;)V

    iget-object v0, p0, Lcom/ninesky/browser/ab;->b:Landroid/app/ProgressDialog;

    invoke-virtual {v0, v3}, Landroid/app/ProgressDialog;->setCancelable(Z)V

    iget-object v0, p0, Lcom/ninesky/browser/ab;->b:Landroid/app/ProgressDialog;

    invoke-virtual {v0, p0}, Landroid/app/ProgressDialog;->setOnCancelListener(Landroid/content/DialogInterface$OnCancelListener;)V

    iget-object v0, p0, Lcom/ninesky/browser/ab;->b:Landroid/app/ProgressDialog;

    invoke-virtual {v0}, Landroid/app/ProgressDialog;->show()V

    invoke-virtual {p0}, Lcom/ninesky/browser/ab;->start()V

    :cond_0
    iget-object v0, p0, Lcom/ninesky/browser/ab;->d:Lcom/ninesky/browser/n;

    iget-object v0, v0, Lcom/ninesky/browser/n;->c:Lcom/ninesky/widget/l;

    invoke-virtual {v0}, Lcom/ninesky/widget/l;->c()V

    iget-object v0, p0, Lcom/ninesky/browser/ab;->d:Lcom/ninesky/browser/n;

    const/4 v1, 0x0

    iput-object v1, v0, Lcom/ninesky/browser/n;->c:Lcom/ninesky/widget/l;

    return-void
.end method

.method public final run()V
    .locals 6

    const/4 v5, 0x0

    iget-object v0, p0, Lcom/ninesky/browser/ab;->d:Lcom/ninesky/browser/n;

    invoke-static {v0}, Lcom/ninesky/browser/n;->a(Lcom/ninesky/browser/n;)Lcom/ninesky/browser/BrowserActivity;

    move-result-object v0

    invoke-virtual {v0}, Lcom/ninesky/browser/BrowserActivity;->getWallpaper()Landroid/graphics/drawable/Drawable;

    move-result-object v0

    :try_start_0
    iget-object v1, p0, Lcom/ninesky/browser/ab;->a:Ljava/net/URL;

    invoke-virtual {v1}, Ljava/net/URL;->openStream()Ljava/io/InputStream;

    move-result-object v1

    if-eqz v1, :cond_0

    iget-object v2, p0, Lcom/ninesky/browser/ab;->d:Lcom/ninesky/browser/n;

    invoke-static {v2}, Lcom/ninesky/browser/n;->a(Lcom/ninesky/browser/n;)Lcom/ninesky/browser/BrowserActivity;

    move-result-object v2

    invoke-virtual {v2, v1}, Lcom/ninesky/browser/BrowserActivity;->setWallpaper(Ljava/io/InputStream;)V
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    :cond_0
    :goto_0
    iget-boolean v1, p0, Lcom/ninesky/browser/ab;->c:Z

    if-eqz v1, :cond_1

    invoke-virtual {v0}, Landroid/graphics/drawable/Drawable;->getIntrinsicWidth()I

    move-result v1

    invoke-virtual {v0}, Landroid/graphics/drawable/Drawable;->getIntrinsicHeight()I

    move-result v2

    sget-object v3, Landroid/graphics/Bitmap$Config;->RGB_565:Landroid/graphics/Bitmap$Config;

    invoke-static {v1, v2, v3}, Landroid/graphics/Bitmap;->createBitmap(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;

    move-result-object v3

    new-instance v4, Landroid/graphics/Canvas;

    invoke-direct {v4, v3}, Landroid/graphics/Canvas;-><init>(Landroid/graphics/Bitmap;)V

    invoke-virtual {v0, v5, v5, v1, v2}, Landroid/graphics/drawable/Drawable;->setBounds(IIII)V

    invoke-virtual {v0, v4}, Landroid/graphics/drawable/Drawable;->draw(Landroid/graphics/Canvas;)V

    :try_start_1
    iget-object v0, p0, Lcom/ninesky/browser/ab;->d:Lcom/ninesky/browser/n;

    invoke-static {v0}, Lcom/ninesky/browser/n;->a(Lcom/ninesky/browser/n;)Lcom/ninesky/browser/BrowserActivity;

    move-result-object v0

    invoke-virtual {v0, v3}, Lcom/ninesky/browser/BrowserActivity;->setWallpaper(Landroid/graphics/Bitmap;)V
    :try_end_1
    .catch Ljava/io/IOException; {:try_start_1 .. :try_end_1} :catch_1

    :goto_1
    iput-boolean v5, p0, Lcom/ninesky/browser/ab;->c:Z

    :cond_1
    iget-object v0, p0, Lcom/ninesky/browser/ab;->b:Landroid/app/ProgressDialog;

    invoke-virtual {v0}, Landroid/app/ProgressDialog;->isShowing()Z

    move-result v0

    if-eqz v0, :cond_2

    iget-object v0, p0, Lcom/ninesky/browser/ab;->b:Landroid/app/ProgressDialog;

    invoke-virtual {v0}, Landroid/app/ProgressDialog;->dismiss()V

    :cond_2
    return-void

    :catch_0
    move-exception v1

    const-string v1, "NSBrowser.Tab"

    const-string v2, "Unable to set new wallpaper"

    invoke-static {v1, v2}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    const/4 v1, 0x1

    iput-boolean v1, p0, Lcom/ninesky/browser/ab;->c:Z

    goto :goto_0

    :catch_1
    move-exception v0

    const-string v0, "NSBrowser.Tab"

    const-string v1, "Unable to restore old wallpaper."

    invoke-static {v0, v1}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_1
.end method
